package loads

import (
	"jvm/instructions/base"
	"jvm/rtda"
)

// DLOAD Load double from local variable
type DLOAD struct{ base.Index8Instruction }

func (dl *DLOAD) Execute(jFrame *rtda.JFrame) {
	_dload(jFrame, dl.Index)
}

type DLOAD_0 struct{ base.NoOperandsInstruction }

func (dl *DLOAD_0) Execute(jFrame *rtda.JFrame) {
	_dload(jFrame, 0)
}

type DLOAD_1 struct{ base.NoOperandsInstruction }

func (dl *DLOAD_1) Execute(jFrame *rtda.JFrame) {
	_dload(jFrame, 1)
}

type DLOAD_2 struct{ base.NoOperandsInstruction }

func (dl *DLOAD_2) Execute(jFrame *rtda.JFrame) {
	_dload(jFrame, 2)
}

type DLOAD_3 struct{ base.NoOperandsInstruction }

func (dl *DLOAD_3) Execute(jFrame *rtda.JFrame) {
	_dload(jFrame, 3)
}

func _dload(jFrame *rtda.JFrame, index uint) {
	val := jFrame.LocalVars().GetDouble(index)
	jFrame.OperandStack().PushDouble(val)
}
